<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('项目简称')" prop="projectAbbreviation">
            <el-input v-model="form.projectAbbreviation" :placeholder="$t('项目简称')" show-word-limit maxlength="32" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('公司名称')" prop="companyName">
            <el-input v-model="form.companyName" :placeholder="$t('公司名称')" show-word-limit maxlength="32" />
          </el-form-item>
        </el-col>
        <Industry ref="industryZj" :buss-data="form" />
        <el-col :span="12">
          <el-form-item :label="$t('细分领域')" prop="segmentation">
            <el-input v-model="form.segmentation" :placeholder="$t('细分领域')" show-word-limit maxlength="32" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('计划投资金额') + $t('金额单位')" prop="planInvestmentAmount">
            <Money v-model="form.planInvestmentAmount" unit="w" :placeholder="$t('计划投资金额')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('是否满足返投要求')">
            <el-select v-model="form.counterInvestmentReq" filterable :placeholder="$t('是否满足返投要求')">
              <el-option
                v-for="dict in counterInvestmentReqOptions"
                :key="dict.dictValue"
                :label="$t(dict.dictLabel)"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('项目简介')" prop="projectIntroduction">
            <el-input v-model="form.projectIntroduction" type="textarea" :placeholder="$t('项目简介')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')" prop="remark">
            <el-input v-model="form.remark" type="textarea" :placeholder="$t('备注')" show-word-limit maxlength="2000" />
          </el-form-item>
        </el-col>
      </el-row>
      <FileTable :list.sync="form.fileList" data-type="bf_reserveItems" :business-id="getDealId" :btn-show="!otherBtnHide" />
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存 取消按钮-->
      <save-btn has-permi="bf:reserveItems" />
    </div>
  </div>
</template>

<script>
    import { saveBfReserveItems, getBfReserveItems } from '@/api/bf/reserveItems/bfReserveItems'
    // 行业组件
    import Industry from '@/components/Industry'
    export default {
        components: {
          Industry
        },
        data() {
            return {
                otherBtnHide: false,
                // 表单参数
                form: {},
                counterInvestmentReqOptions: [],
                // 项目id
                getDealId: this.$route.query.id,
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {
                  projectAbbreviation: [{ required: true, message: this.$t('必填信息'), trigger: 'change' }]
                }
            }
        },
        created() {
          this.getDicts('sys_yes_no').then(response => {
            this.counterInvestmentReqOptions = response.data
          })
        },
        methods: {
            // 初始化数据
            init(data) {
                if (data != null && data.id !== undefined) {
                    getBfReserveItems(data.id).then(response => {
                        this.form = response.data
                        this.loading = false
                        this.$nextTick(() => {
                          this.$refs.industryZj.initIndustrySecond()
                        })
                        this.loading = false
                    })
                } else {
                    this.reset()
                }
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    dealId: this.$route.query.id,
                    companyName: undefined,
                    projectAbbreviation: undefined,
                    industryFirst: undefined,
                    industrySecond: undefined,
                    segmentation: undefined,
                    planInvestmentAmount: undefined,
                    counterInvestmentReq: undefined,
                    projectIntroduction: undefined,
                    remark: undefined,
                    createBy: undefined,
                    createTime: undefined,
                    updateBy: undefined,
                    updateTime: undefined,
                    delFlag: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                  this.$parent.$parent.formOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveBfReserveItems(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                      this.locationError(document)
                    }
                })
           }

        }

    }
</script>
